const Koa = require('koa')

const koaBody = require('koa-body')

const path = require('path')

const Router = require('koa-router')

const app = new Koa()

const router = new Router()

app.use(koaBody())
app.use(async(ctx, next) => {
    ctx.set("Access-Control-Allow-Origin", "*");
    ctx.set("Access-Control-Allow-Methods", "PUT, POST, GET, DELETE, OPTIONS");
    // 请求头设置
    ctx.set(
        "Access-Control-Allow-Headers",
        `Content-Type, Content-Length, Authorization, Accept, X-Requested-With , yourHeaderFeild,x-token,sessionToken,token`
    );
    if (ctx.method == "OPTIONS") {
        ctx.body = 200;
    } else {
        await next();
    }
})

// 导入自定义的路由模块
const UserRouter = require('./router/User')
const ShopRouter = require('./router/Shop')
const OrderRouter = require('./router/Order')

app.use(router.routes())


app.use(UserRouter.routes())

app.use(ShopRouter.routes())

app.use(OrderRouter.routes())

app.listen(7777,(ctx)=>{
    console.log('可莉,启动!!!');
})